package Message;

import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import Server.SQLConnection;
import OCSF.*;

public class MessageLogout extends Message {
	


	
	
	public MessageLogout(String[] str, ConnectionToClient client)
	{
		super(str,client);
	}
	
	public void execute() throws SQLException, IOException
	{
		
		PreparedStatement ps2=conn.getConnection().prepareStatement("UPDATE test.Workers SET Connected=? WHERE idWorker=?;");
		
		if(str[1].equals("Worker"))
		{
			ps2.setInt(1, 0);
			ps2.setString(2, str[2]);
			ps2.executeUpdate();
			ps2.close();
			client.sendToClient("LogoutSuccess");
		}
		
	}
	
}
